package thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import util.MathUtil;

public class Thread1 {
    //线程是否都需要在方法中创建？
    //可以在方法之外创建线程，但是需要在方法中启动
    static Runnable r1 = ()-> System.out.println("静态线程");


    public static void main(String[] args) throws InterruptedException {
//        new Thread(r1).start();

        new Thread1().t1();
        Thread.sleep(1000 * 15);

    }

    private void t1() {


        AtomicInteger m = new AtomicInteger(0);

        CompletableFuture.runAsync(() -> System.out.println("go execute 1:" + m));

        for (int i = 0; i < 20; i++) {
            MathUtil.resolvePrime();
        }

        m.set(1);
//        m = 1;
//        Integer finalM = m;

        // 这里有输出语句才会输出
        System.out.println("math finished");

        CompletableFuture.runAsync(() -> System.out.println("go execute 2:" + m));

    }
}
